import random

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

from Base.PublicFunction import OpenBroswer
class Object:
    def __init__(self):
        self.dr=OpenBroswer.openbrower()
        self.dr.get('http://10.10.10.171:8080/WoniuBoss4.0/login')
        self.dr.find_element_by_name('userName').send_keys('WNCD000')
        self.dr.find_element_by_name('userPass').send_keys('woniu123')
        self.dr.find_element_by_xpath('/html/body/div[1]/div/div/div[2]/button').click()
        # self.dr.implicitly_wait(10)

    # def closeBroswer(self):
    #     self.dr.close()

    def findElement(self,locator):
        ele = WebDriverWait(self.dr, 10, 0.1).until(EC.presence_of_element_located(locator))
        return ele

    # def get_username(self):
    #     locator = (By.NAME,'userName')
    #     ele = self.findElement(locator)
    #     return ele

    # def username(self):
    #     locator = (By.NAME,'userName')
    #     ele = self.findElement(locator)
    #     return ele
    #
    # def password(self):
    #     locator = (By.NAME, 'userPass')
    #     ele = self.findElement(locator)
    #     return ele
    #
    # def veryficode(self):
    #     locator = (By.CLASS_NAME, 'col-md-6.text.verification')
    #     ele = self.findElement(locator)
    #     return ele
    #
    # def logion_button(self):  #登录按钮
    #     locator = (By.CLASS_NAME, 'btn.btn-primary.btn-block.btn-save')
    #     ele = self.findElement(locator)
    #     return ele

    def cls_management(self):  #班务管理
        locator = (By.XPATH, '/html/body/div[4]/div[2]/div[8]/div[1]/a')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[4]/div[2]/div[8]/div[1]/a')

    def cls_manage(self):  #班级管理
        locator = (By.XPATH, '/html/body/div[4]/div[2]/div[8]/div[2]/div/ul/li[1]/a')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[4]/div[2]/div[8]/div[2]/div/ul/li[1]/a')

    def stu_checking(self):  #学员考勤
        locator = (By.XPATH, '/html/body/div[4]/div[2]/div[8]/div[2]/div/ul/li[2]/a')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[4]/div[2]/div[8]/div[2]/div/ul/li[2]/a')

    def stu_leave(self):  #学院请假
        locator = (By.XPATH, '/html/body/div[4]/div[2]/div[8]/div[2]/div/ul/li[3]/a')
        ele = self.findElement(locator)
        return ele


    def stu_change(self):  #学员转班
        locator = (By.XPATH, '/html/body/div[4]/div[2]/div[8]/div[2]/div/ul/li[4]/a')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[4]/div[2]/div[8]/div[2]/div/ul/li[4]/a')

    def add_button(self):  #新增按钮
        locator = (By.CLASS_NAME, 'btn.btn-primary.btn-padding.pull-right')
        ele = self.findElement(locator)
        return ele
        # return  self.dr.find_element_by_class_name('btn.btn-primary.btn-padding.pull-right')

    def cls_num(self):  #班号
        locator = (By.NAME, 'c.class_no')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_name('c.class_no')

    def direction(self):  #方向
        locator = (By.CLASS_NAME, 'sel-text.stu-orientation')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_class_name('sel-text.stu-orientation')

    def start_cls(self):  #开班时间
        locator = (By.CLASS_NAME, 'text.date')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_class_name('text.date')

    def start_cls_time(self):  #选择开班时间
        locator = (By.XPATH, '/html/body/div[9]/div[3]/table/tbody/tr[2]/td[1]')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[9]/div[3]/table/tbody/tr[2]/td[1]')
    def teacher(self):  #班主任
        locator = (By.NAME, 'c.class_headmaster_id')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_name('c.class_headmaster_id')

    def save_button(self):  #保存按钮
        locator = (By.XPATH, '/html/body/div[11]/div/div/div[3]/button')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[11]/div/div/div[3]/button')

    def button_add1(self):  #新增按钮1    -学员请假
        locator = (By.XPATH, '/html/body/div[8]/div[2]/div/div/div/div[1]/div/button')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[8]/div[2]/div/div/div/div[1]/div/button')

    def start_time(self):   #开始时间
        locator = (By.XPATH, '/html/body/div[15]/div/div/div[2]/form/div[1]/div[1]/input')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[15]/div/div/div[2]/form/div[1]/div[1]/input')

    def select_start_time(self):  # 选择开始时间
        locator = (By.XPATH, '/html/body/div[11]/div[3]/table/tbody/tr[5]/td[1]')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[11]/div[3]/table/tbody/tr[5]/td[1]')

    def end_time(self):   #结束时间
        locator = (By.XPATH, '/html/body/div[16]/div/div/div[2]/form/div[1]/div[2]/input')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[16]/div/div/div[2]/form/div[1]/div[2]/input')

    def select_end_time(self):  # 选择结束时间
        locator = (By.XPATH, '/html/body/div[12]/div[3]/table/tbody/tr[5]/td[7]')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[12]/div[3]/table/tbody/tr[5]/td[7]')

    def type_leave(self):  #请假类型 下拉框
        locator = (By.XPATH, '/html/body/div[16]/div/div/div[2]/form/div[2]/div[1]/select')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[16]/div/div/div[2]/form/div[2]/div[1]/select')

    def leave_day(self):  #请假天数
        locator = (By.XPATH, '/html/body/div[16]/div/div/div[2]/form/div[2]/div[2]/input')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[16]/div/div/div[2]/form/div[2]/div[2]/input')

    def stu_name(self):   #学生姓名
        locator = (By.XPATH, '/html/body/div[16]/div/div/div[2]/form/div[3]/div/input')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[16]/div/div/div[2]/form/div[3]/div/input')

    def stu_name_button(self):   #输入学生姓名 带出来的下拉框
        locator = (By.XPATH, '/html/body/div[16]/div/div/div[2]/form/div[3]/div/ul')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[16]/div/div/div[2]/form/div[3]/div/ul')

    def deduct(self):    #扣分  下拉框
        locator = (By.XPATH, '/html/body/div[16]/div/div/div[2]/form/div[3]/select')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[16]/div/div/div[2]/form/div[3]/select')

    def leave_cause(self):  #请假原因
        locator = (By.XPATH, '/html/body/div[16]/div/div/div[2]/form/div[4]/div/textarea')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[16]/div/div/div[2]/form/div[4]/div/textarea')

    def save_button1(self):  #保存按钮  -学员请假
        locator = (By.XPATH, '/html/body/div[16]/div/div/div[3]/button')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[16]/div/div/div[3]/button')

    def keepout_view(self):  #防遮挡
        locator = (By.XPATH, '/html/body/div[16]/div/div/div[2]')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[16]/div/div/div[2]')

    def region(self):      #区域
        locator = (By.XPATH, '/html/body/div[8]/div[2]/div/div/div/div[1]/select[1]')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[8]/div[2]/div/div/div/div[1]/select[1]')

    def status_leave(self):  #请假状态
        locator = (By.XPATH, '/html/body/div[8]/div[2]/div/div/div/div[1]/select[2]')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[8]/div[2]/div/div/div/div[1]/select[2]')

    def leave_stu_name(self): #请假学生姓名
        locator = (By.XPATH, '/html/body/div[8]/div[2]/div/div/div/div[1]/input')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[8]/div[2]/div/div/div/div[1]/input')

    def select_button(self):  #查询按钮
        locator = (By.XPATH, '/html/body/div[8]/div[2]/div/div/div/div[1]/button')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[8]/div[2]/div/div/div/div[1]/button')

    def leave_cls(self):    #转班按钮
        index = random.randint(2,8)  #实现随机修改
        locator = (By.XPATH, '/html/body/div[8]/div[2]/div/div/div/div[2]/div[2]/div[2]/table/tbody/tr['+str(index)+']/td[12]/button')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[8]/div[2]/div/div/div/div[2]/div[2]/div[2]/table/tbody/tr['+str(index)+']/td[12]/button')

    def school_region(self): #校区
        locator = (By.NAME, 'changeRegion')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_name('changeRegion')

    def change_cls(self):  #转班级
        locator = (By.NAME, 'changeClass')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_name('changeClass')

    def accept_button(self):  #确定按钮
        locator = (By.XPATH, '/html/body/div[9]/div/div/div[3]/button')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[9]/div/div/div[3]/button')

    def accept(self):  #二次确定
        locator = (By.XPATH, '/html/body/div[11]/div/div/div[3]/button[2]')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[11]/div/div/div[3]/button[2]')

    def stu_leave_table(self): #学员请假表
        locator = (By.CLASS_NAME, 'table.table-hover.table-bordered.table-striped')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_class_name('table.table-hover.table-bordered.table-striped')

    def stu_change_cls(self):  #学员转班表
        locator = (By.CLASS_NAME, 'fixed-table-container')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_class_name('fixed-table-container')

    def change_cls_success(self): #转班成功提示框
        locator = (By.XPATH, '/html/body/div[10]/div/div/div[2]/div')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[10]/div/div/div[2]/div')

    def cls_room(self):  #班级
        locator = (By.XPATH, '/html/body/div[8]/div[2]/div/div/div/div[1]/select[2]')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[8]/div[2]/div/div/div/div[1]/select[2]')

    def search_button(self):  #搜索按钮
        locator = (By.XPATH, '/html/body/div[8]/div[2]/div/div/div/div[1]/button')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[8]/div[2]/div/div/div/div[1]/button')

    def tableObj(self):   #表单对象
        locator = (By.CLASS_NAME, 'table.table-hover.table-bordered.table-striped')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_class_name('table.table-hover.table-bordered.table-striped')

    def add_success(self):  #新增班级成功
        locator = (By.XPATH, '/html/body/div[11]/div/div/div[3]/button')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[11]/div/div/div[3]/button')

    def add_button1(self):  #点击确定
        locator = (By.XPATH, '/html/body/div[8]/div[2]/div/div/div/div[1]/button')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[8]/div[2]/div/div/div/div[1]/button')

    def login_out(self):
        locator = (By.LINK_TEXT, '[注销]')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_link_text('[注销]')

    def add(self):   #新增
        locator = (By.CLASS_NAME, 'btn.btn-primary.btn-padding.pull-right')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_class_name('btn.btn-primary.btn-padding.pull-right')

    def accept1(self):
        locator = (By.XPATH, '/html/body/div[10]/div/div/div[3]/button')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[10]/div/div/div[3]/button')

    def souso(self):
        locator = (By.XPATH, '/html/body/div[8]/div[2]/div/div/div/div[1]/button')
        ele = self.findElement(locator)
        return ele
        # return self.dr.find_element_by_xpath('/html/body/div[8]/div[2]/div/div/div/div[1]/button')
























